//index.js用于API统一管理
import requests from "./requests";
import mockRequests from "./mockAjax";
export const reqCatagoryList = () => {
  //发请求,返回一个promise对象
  return requests({
    url: "/product/getBaseCategoryList",
    method: "get",
  });
};
//获取首页轮播图的接口
export const reqGetBannerList = () => {
  return mockRequests({
    url: "/banner",
    method: "get",
  });
};
//获取floor数据
export const reqFloorList = () => {
  return mockRequests({
    url: "/floor",
    method: "get",
  });
};
//获取搜索模块的数据
export const reqGetSearchInfo = (params) => {
  return requests({
    url: "/list",
    method: "post",
    data: params, //参数
  });
};
export const reqGoodsInfo = (skuId) => {
  return requests({
    url: `/item/${skuId}`,
    method: "get",
  });
};
//将产品添加到购物车中或者更新某个产品的个数
export const reqAddOrUpdateShopCart = (skuId, skuNum) => {
  return requests({
    url: `/cart/addToCart/${skuId}/${skuNum}`,
    method: "post",
  });
};
//获取购物车列表数据接口
export const reqCartList = () => {
  return requests({
    url: "/cart/cartList",
    method: "GET",
  });
};
//删除购物车数据
export const reqDeleteCartById = (skuId) => {
  return requests({
    url: `/cart/deleteCart/${skuId}`,
    method: "delete",
  });
};
//修改商品选中状态
export const reqUpdateCheckedById = (skuId, isChecked) => {
  return requests({
    url: `/cart/checkCart/${skuId}/${isChecked}`,
    method: "get",
  });
};
//获取验证码
export const reqGetCode = (phone) => {
  return requests({
    url: `/user/passport/sendCode/${phone}`,
    method: "get",
  });
};
//注册
export const reqUserRegister = (data) => {
  return requests({
    url: "/user/passport/register",
    data,
    method: "post",
  });
};
//登录
export const reqUserLogin = (data) => {
  return requests({
    url: "/user/passport/login",
    data,
    method: "post",
  });
};
//获取用户信息（需要带着用户token向服务器索要用户信息）
export const reqUserInfo = () => {
  return requests({
    url: "/user/passport/auth/getUserInfo",
    method: "get",
  });
};
//退出登录
export const reqLogOut = () => {
  return requests({
    url: "/user/passport/logout",
    method: "get",
  });
};
//获取用户地址
export const reqAddressInfo = () => {
  return requests({
    url: "/user/userAddress/auth/findUserAddressList",
    method: "get",
  });
};
//获取订单交易页信息
export const reqOrderInfo = () => {
  return requests({
    url: "/order/auth/trade",
    method: "get",
  });
};
//提交订单
export const reqSubmitOrder = (tradeNo, data) => {
  return requests({
    url: `/order/auth/submitOrder?tradeNo=${tradeNo}`,
    data,
    method: "post",
  });
};
//获取支付信息
export const reqPayInfo = (orderId) => {
  return requests({
    url: `/payment/weixin/createNative/${orderId}`,
    method: "get",
  });
};
//获取支付状态
export const reqPayStatus = (orderId) => {
  return requests({
    url: `/payment/weixin/queryPayStatus/${orderId}`,
    method: "get",
  });
};
//获取个人中心数据
export const reqMyOrderList = (page, limit) => {
  return requests({
    url: `/order/auth/${page}/${limit}`,
    method: "get",
  });
};
